#include "../drivers/port.h"
#include "../drivers/screen.h"
#include "util.h"
#include "../cpu/isr.h"
#include "../cpu/timer.h"
#include "../drivers/keyboard.h"

void main() {
    isr_install();
    __asm__ __volatile__("sti");
    // init_timer(50);

    init_keyboard();
}
void test005() {
    isr_install();
    __asm__ __volatile__("sti");
    init_timer(50);
}

void test004() {
    isr_install();
    __asm__ __volatile__("int $2");
    __asm__ __volatile__("int $3");
}

void test003() {
    clear_screen();

    /* Fill up the screen */
    int i = 0;
    for (i = 0; i < 24; i++) {
        char str[255];
        int_to_ascii(i, str);
        kprint_at(str, 0, i);
    }

    kprint_at("This text forces the kernel to scroll. Row 0 will disappear. ", 60, 24);
    kprint("And with this text, the kernel will scroll again, and row 1 will disappear too!");
}

void test002() {
    clear_screen();
    kprint_at("X", 1, 6);
    kprint_at("This is text spans multiple lines", 75, 10);
    kprint_at("There is a line\nbreak", 0, 20);
    kprint("There is a line\nbreak");
    kprint_at("what happens when we run out of space?", 45, 24);
}


int test001() {
    char* video_memory = (char*) 0xb8000;
    *video_memory = 'X';

    /* Screen cursor position: ask VGA control register (0x3d4) for bytes
    /* 14 = high byte of cursor and 15 = low byte of cursor. */
    port_byte_out(0x3d4, 14);

    int position = port_byte_in(0x3d5);/* high byte */
    position = position << 8;

    port_byte_out(0x3d4, 15);/* requesting low byte */
    position += port_byte_in(0x3d5);

    int offset_from_vag = position * 2;

    char *vga = (char*) 0xb8000;
    vga[offset_from_vag] = 'X';
    vga[offset_from_vag + 1] = 0x0f;
    return 0;
}
